﻿using System;
using Microsoft.Xna.Framework.Graphics;
using ShevaEngine.Core.Interfaces;

namespace ShevaEngine.Core.Modules.Graphics
{
    /// <summary>
    /// Draw call.
    /// </summary>
    public class UserIndexedPrimitivesDrawCall<T> : DrawCall where T : struct, IVertexType
    {
        /// <summary>Typ primitiva.</summary>
        public PrimitiveType PrimitiveType;
        /// <summary>Vertices;</summary>
        public T[] Vertices;
        /// <summary>Indices.</summary>
        public Int32[] Indices;
        /// <summary>The number of primitives to render.</summary>
        public int PrimitiveCount;
        
        /// <summary>
        /// Konstruktor.
        /// </summary>
        public UserIndexedPrimitivesDrawCall(PrimitiveType primitiveType, T[] data, Int32[] indices, Int32 primitiveCount)
            : base()
        {
            this.PrimitiveType = primitiveType;
            this.Vertices = data;
            this.Indices = indices;
            this.PrimitiveCount = primitiveCount;
        }

        /// <summary>
        /// Metoda vykresli objekt
        /// </summary>
        public override void Render()
        {
            ShevaEngine.Instance.GraphicsDevice.DrawUserIndexedPrimitives<T>(this.PrimitiveType, 
                this.Vertices, 0, this.Vertices.Length,
                this.Indices, 0, this.PrimitiveCount);
        }

        /// <summary>
        /// Metoda vykresli objekt
        /// </summary>
        public override void RenderHWInstancing(int instancesCount)
        {
            throw new Exception("Impossible !");
        }       
    }
}
